using System;
using System.Collections.Generic;
using System.Windows;
namespace Microsoft.Expression.Drawing.Core
{
	internal class SimpleSegment
	{
		public enum SegmentType
		{
			Line,
			CubicBeizer
		}
		public SimpleSegment.SegmentType Type
		{
			get;
			private set;
		}
		public Point[] Points
		{
			get;
			private set;
		}
		public void Flatten(IList<Point> resultPolyline, double tolerance, IList<double> resultParameters)
		{
			switch (this.Type)
			{
			case SimpleSegment.SegmentType.Line:
				resultPolyline.Add(this.Points[1]);
				if (resultParameters != null)
				{
					resultParameters.Add(1.0);
					return;
				}
				break;
			case SimpleSegment.SegmentType.CubicBeizer:
				BezierCurveFlattener.FlattenCubic(this.Points, tolerance, resultPolyline, true, resultParameters);
				break;
			default:
				return;
			}
		}
		private SimpleSegment()
		{
		}
		public static SimpleSegment Create(Point point0, Point point1)
		{
			return new SimpleSegment
			{
				Type = SimpleSegment.SegmentType.Line,
				Points = new Point[]
				{
					point0,
					point1
				}
			};
		}
		public static SimpleSegment Create(Point point0, Point point1, Point point2)
		{
			Point point3 = GeometryHelper.Lerp(point0, point1, 0.66666666666666663);
			Point point4 = GeometryHelper.Lerp(point1, point2, 0.33333333333333331);
			return new SimpleSegment
			{
				Type = SimpleSegment.SegmentType.CubicBeizer,
				Points = new Point[]
				{
					point0,
					point3,
					point4,
					point2
				}
			};
		}
		public static SimpleSegment Create(Point point0, Point point1, Point point2, Point point3)
		{
			return new SimpleSegment
			{
				Type = SimpleSegment.SegmentType.CubicBeizer,
				Points = new Point[]
				{
					point0,
					point1,
					point2,
					point3
				}
			};
		}
	}
}
